package com.da.javatest.interview.session2;

import java.util.concurrent.atomic.AtomicReference;

import lombok.Data;

/**
 * @author chenlida
 * @date 2020/3/29 14:57
 * @description 对象引用
 */
public class Test05AtomicReference {
    public static void main(String[] args) {
        User zs = new User(1, "张三");
        User ls = new User(2, "李四");

        AtomicReference<User> ar = new AtomicReference<>();
        ar.set(zs);

        System.out.println(ar.compareAndSet(zs, ls) + " " + ar.get());
        System.out.println(ar.compareAndSet(zs, ls) + " " + ar.get());
    }
}

@Data
class User {
    private Integer id;
    private String name;

    public User(Integer id, String name) {
        this.id = id;
        this.name = name;
    }
}
